<template>
	<div class="statistics-container" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
		<div class="pull-refresh" :style="{ height: refreshHeight + 'px' }" v-if="1">
			<div v-if="refreshHeight>0">{{ refreshText }}</div>
		</div>
		<!-- 头部标题 -->
		<div class="header">
			<span class="title">{{datainfo.member_info && datainfo.member_info.nickname}}</span>
		</div>

		<!-- 今日数据概览 -->
		<div class="data-overdiv">
			<div class="overdiv-header">
				<span class="header-title">近7日数据</span>
			</div>
			<div class="overdiv-grid">
				<div class="grid-item">
					<div class="item-label">浏览</div>
					<div class="item-value">{{datainfo.pageviews || 0}}</div>
					<!-- <div class="item-value">{{pageviews1 || 0}}</div> -->
					<div class="item-trend up">{{datainfo.pageviews_ratio || 0}}%</div>
				</div>
				<div class="grid-item">
					<div class="item-label">互动数</div>
					<div class="item-value">{{datainfo.interaction || 0}}</div>
					<div class="item-trend up">{{datainfo.interaction_ratio|| 0}}%</div>
				</div>
				<div class="grid-item">
					<div class="item-label">新增粉丝</div>
					<div class="item-value">{{datainfo.fans || 0}}</div>
					<div class="item-trend up">{{datainfo.fans_ratio || 0}}%</div>
				</div>
				<div class="grid-item">
					<div class="item-label">主页访客</div>
					<div class="item-value">{{datainfo.home_view || 0}}</div>
					<div class="item-trend up">{{datainfo.home_view_ratio || 0}}%</div>
				</div>
			</div>
			<!-- 示例笔记 -->
			<div class="note-prediv" @click="toDetail" v-if="datainfo.member_note">
				<img class="note-image" :src="datainfo.member_note && datainfo.member_note.pic"/>

				<div class="note-info">
					<div class="note-info-flex">
						<span class="note-t" :style="{ background:  $store.state.theme.colors.color2 }">最新笔记</span>
						<span class="note-title">{{datainfo.member_note && datainfo.member_note.title}}！</span>
					</div>
					<div class="note-stats">
						<span>浏览 {{datainfo.pageviews || 0}}</span>
						<span>点赞 {{datainfo.thumbs || 0}}</span>
						<span>评论 {{datainfo.comments || 0}}</span>
					</div>
				</div>
				<div class="note-info-span"> 更多> </div>
			</div>
		</div>
		<div class="trend-section">
			<div class="trend-header">
				<span class="section-title">商品带货分析</span>
				<div class="date-range">
					<span>日期范围</span>
					<span class="note-t" :style="{ background: $store.state.theme.colors.color2 }" @click="getdata(0)">近七日</span>
					<span class="note-t" @click="showPicker = true" :style="{ background: $store.state.theme.colors.color2 }">近一个月</span>
				</div>
			</div>

			<!-- 手动引入的组件 -->
			<!-- <uni-datetime-picker  v-model="range" type="daterange" @maskClick="maskClick" /> -->


			<van-calendar v-model="showPicker" type="range" @confirm="confirm" :color="$store.state.theme.colors.color1"  :min-date="minDate"
			:max-date="maxDate"/>

			<div class="data-table-container">
				<div class="data-table">
					<!-- 表头 -->
					<div class="table-row header-row" :style="{background:$store.state.theme.colors.color1}">
						<span class="table-cell rank-cell">排名</span>
						<span class="table-cell product-cell">商品</span>
						<span class="table-cell amount-cell">销售额（元）</span>
						<span class="table-cell volume-cell">销量</span>
						<span class="table-cell rate-cell">转化率</span>
					</div>

					<!-- 表格内容 -->
					<div class="table-body">
						<template v-if="productData &&  productData.length>0">
							<div class="table-row" v-for="(item, index) in product_Data" :key="index">
								<span class="table-cell rank-cell">{{ (currentPage_product - 1) * pageSize_product + index + 1 }}</span></span>
								<div class="table-cell product-cell">
									<span class="product-name">{{ item.name }}</span>
								</div>
								<span class="table-cell amount-cell">{{ item.totalprice }}</span>
								<span class="table-cell volume-cell">{{ item.num }}</span>
								<span class="table-cell rate-cell">{{ item.all_commission }}%</span>
							</div>
						</template>
						<template v-else>
							<div class="nodata-box" >
								暂无数据
							</div>
						</template>
					</div>
				</div>
				<!-- 分页控件 -->
				<div class="pagination" v-if="productData &&  productData.length>0">
					<button class="page-btn" :disabled="currentPage_product === 1" @click="product_prevPage">上一页</button>
					<span class="page-info">第 {{ currentPage_product }} 页 / 共 {{ productPages }} 页</span>
					<button class="page-btn" :disabled="currentPage_product === productPages" @click="product_nextPage">下一页</button>
				</div>
			</div>
		</div>
		<!-- 	<div class="trend-section">
			<div class="trend-header">
				<div class="section-title">
					<span class="section-title-left">用户来源分析</span>
					<span class="section-title-right">统计周期04-21至04-26
					</span>
				</div>
				<div class="date-range">
					<span>日期范围</span>
					<span class="note-t" :style="{ background: $store.state.theme.colors.color1 }">近七日</span>
				</div>
			</div>
			 <div class="pie-legend">
				<div class="legend-item">
					<div class="legend-color" style="background: #4ecb73"></div>
					<span>搜索 84%</span>
				</div>
				<div class="legend-item">
					<div class="legend-color" style="background: #2b85e4"></div>
					<span>首页推荐 10%</span>
				</div>
				<div class="legend-item">
					<div class="legend-color" style="background: #ff9900"></div>
					<span>关注页面 4%</span>
				</div>
				<div class="legend-item">
					<div class="legend-color" style="background: #ed3f14"></div>
					<span>个人主页 2%</span>
				</div>
				<div class="legend-item">
					<div class="legend-color" style="background: #ed3f14"></div>
					<span>其他来源 2%</span>
				</div>
			</div> 
		</div> -->
		<!-- 账号数据趋势 -->
		<div class="trend-section">
			<div class="trend-header">
				<span class="section-title">用户画像分析</span>
				<div class="date-range">
					<span>日期范围</span>
					<span class="note-t" :style="{ background: $store.state.theme.colors.color2 }" @click="getdata(0)">近七日</span>
					<span class="note-t" @click="showPicker2 = true" :style="{ background: $store.state.theme.colors.color2 }">近一个月</span>
				</div>
			</div>
			<!-- <uni-datetime-picker v-if="showPicker2" v-model="range2" type="daterange" @maskClick="maskClick" /> -->
			<van-calendar v-model="showPicker2" type="range" @confirm="confirm" :color="$store.state.theme.colors.color1"  :min-date="minDate"
			:max-date="maxDate"/>
			<div class="trend-chart">
				<!-- <div class="chart-header">
					<div class="chart-header-border">
						<div class="chart-label">观看</div>
						<div class="chart-value">367</div>
					</div>
					<div class="chart-header-border">
						<div class="chart-label">观看总时长</div>
						<div class="chart-value">36</div>
					</div>
					<div class="chart-header-border">
						<div class="chart-label">主页访客</div>
						<div class="chart-value">11</div>
					</div>
				</div> -->
				<div class="year-box">
					性别
				</div>
				<div class="chart-container">
					<!-- <echart ref="pieChart" :option="option" canvasId="pieChart"></echart> -->
					<PieChart :data="sex_list"  :option="option"></PieChart>
				
				</div>
				<div class="year-box">
					年龄分布
				</div>
				<!-- 折线图 -->
				<div class="chart-container">
					<!-- <echart ref="lineChart" :option="option2" canvasId="lineChart"></echart> -->
					<BarChart :data="{xdata:age_list,ydata:dateRange}" :option="option2"></BarChart>
				</div>
			</div>
			<div class="year-box">
				地域分布
			</div>
			<div class="data-table-container">
				<div class="data-table">
					<!-- 表头 -->
					<div class="table-row header-row" :style="{background:$store.state.theme.colors.color1}">
						<span class="table-cell city-num-cell">排名</span>
						<span class="table-cell city-cell">省份</span>
						<span class="table-cell city-num-cell">人数</span>
						<span class="table-cell city-num-cell">占比</span>
					</div>

					<!-- 表格内容 -->
					<div class="table-body">
						<template v-if="paginatedData && paginatedData.length>0">
							<div class="table-row" v-for="(item, index) in paginatedData" :key="index">
								<span class="table-cell city-num-cell">
									{{ (currentPage - 1) * pageSize + index + 1 }}</span>
								<div class="table-cell city-cell">
									<span class="product-name">{{ item.province }}</span>
								</div>
								<span class="table-cell city-num-cell">{{ item.num }}</span>
								<span class="table-cell city-num-cell">{{ item.radio }}%</span>
							</div>
						</template>
						<template v-else>
							<div class="nodata-box" >
								暂无数据
							</div>
						</template>
					</div>
				</div>
				<!-- 分页控件 -->
				<div class="pagination" v-if="paginatedData && paginatedData.length>0">
					<button class="page-btn" :disabled="currentPage === 1" @click="prevPage">上一页</button>
					<span class="page-info">第 {{ currentPage }} 页 / 共 {{ totalPages }} 页</span>
					<button class="page-btn" :disabled="currentPage === totalPages" @click="nextPage">下一页</button>
				</div>
			</div>

		</div>


		<!-- 来源分析 -->
		<!-- <div class="source-analysis">
			<div class="analysis-header">
				<span class="section-title">观众来源分析</span>
				<div class="date-selector">
					<span class="active">日期范围</span>
					<span class="note-t" :style="{ background: $store.state.theme.colors.color1 }">近七日</span>
				</div>
			</div>
			<div class="pie-chart">
				
				<div class="pie-container">
					<echart ref="pieChart" :option="option" canvasId="pieChart"></echart>
					<div class="pie-legend">
						<div class="legend-item">
							<div class="legend-color" style="background: #4ecb73"></div>
							<span>搜索 84%</span>
						</div>
						<div class="legend-item">
							<div class="legend-color" style="background: #2b85e4"></div>
							<span>个人主页 10%</span>
						</div>
						<div class="legend-item">
							<div class="legend-color" style="background: #ff9900"></div>
							<span>其他入口 4%</span>
						</div>
						<div class="legend-item">
							<div class="legend-color" style="background: #ed3f14"></div>
							<span>个人主页 2%</span>
						</div>
					</div>
				</div>
			</div>
		</div> -->

		<!-- 优质笔记 -->
		<div class="quality-notes">
			<div class="notes-header">
				<span class="section-title">优质笔记</span>
			</div>
			<div class="notes-list">
				<div class="note-item" v-for="(item,index) in quality_list" :key="index">
					<img class="note-image" :src="item.pic">
					</img>
					<div class="note-content">
						<div class="note-span">{{item.title}}</div>
						<div class="note-tag">
							<div class="flex-a" :style="{ background: $store.state.theme.colors.color2 }" v-if="item.is_max_thumbs == 1">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/de0fb06ed544f7d77bdf74a339c256c3.png"
									mode=""/>
								点赞最多
							</div>
							<div class="flex-a" :style="{ background: $store.state.theme.colors.color2 }" v-if="item.is_max_pageviews == 1">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/bbf822261509059c34877f9556922219.png"
									mode=""/>
								观看最多
							</div>
							<div class="flex-a" :style="{ background: $store.state.theme.colors.color2 }" v-if="item.is_max_comments == 1">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/ea1769ca95adb3baf1bade419ce7ec40.png"
									mode=""/>
								评论最多
							</div>
							<div class="flex-a" :style="{ background: $store.state.theme.colors.color2 }" v-if="item.is_max_pageviews == 1">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/081145f05aa168dd392f9391e82d2434.png"
									mode=""/>
								收藏最多
							</div>
						</div>
						<div class="note-interactions">
							<div class="flex-a">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/de0fb06ed544f7d77bdf74a339c256c3.png"
									mode=""/>
								{{item.thumbs}}
							</div>
							<div class="flex-a">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/bbf822261509059c34877f9556922219.png"
									mode=""/>
								{{item.pageviews}}
							</div>
							<div class="flex-a">
								<img class="note-interactions-icon"
									src="https://hedashepin.oss-cn-guangzhou.aliyuncs.com/upload/3/20250410/ea1769ca95adb3baf1bade419ce7ec40.png"
									mode=""/>
								{{item.comments}}
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import { getNoteMemberStatistics } from "@/api/note";
import { appIndex } from "@/api/user";
import PieChart from "@/components/echarts/PieChart";
import BarChart from "@/components/echarts/BarChart";
import LineChart from "@/components/echarts/LineChart";
// var app = getApp();
import echart from "../../components/echart/echarts-uniapp/echarts-uniapp.vue";
import uniDatetimePicker from "../../components/echart/uni-datetime-picker/uni-datetime-picker.vue";
export default {
  data() {
    return {
      refreshHeight: 0,
      startY: 0,
      refreshText: "下拉刷新",
      isRefreshing: false,
      maxPullHeight: 80,
      option: {},
      option2: {},
      datainfo: {},
      dateRange: [
        "17岁以下",
        "18-24岁",
        "25-29岁",
        "30-39岁",
        "40-49岁",
        "50岁以上",
        "未知",
      ],
      showPicker: false,
      showPicker2: false,
      range: [],
      range2: [],
      sex_list: [],
      age_list: [],
      quality_list: [],
      productData: [],
      cityData: [],
      currentPage_product: 1,
      pageSize_product: 5,
      currentPage: 1,
      pageSize: 5,
      minDate: new Date(new Date().setDate(new Date().getDate() - 30)),
      maxDate: new Date(),
      pageviews1: 0,
    };
  },
  computed: {
    // 分页后的数据
    product_Data() {
      const start = (this.currentPage_product - 1) * this.pageSize_product;
      const end = start + this.pageSize_product;
      return this.productData.slice(start, end);
    },
    // 总页数
    productPages() {
      return Math.ceil(this.productData.length / this.pageSize_product);
    },
    // 分页后的数据
    paginatedData() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.cityData.slice(start, end);
    },
    // 总页数
    totalPages() {
      return Math.ceil(this.cityData.length / this.pageSize);
    },
  },
  components: {
    echart,
    uniDatetimePicker,
    PieChart,
    LineChart,
    BarChart,
  },
  watch: {
    range(newval) {
      return;
      const that = this;
      const [start_day, end_day] = that.range;
      that.showPicker = false;
      app.get(
        "MemberNote/noteMemberStatistics",
        {
          start_day: start_day,
          end_day: end_day,
        },
        function (res) {
          that.loaded();
          if (res.status == 200) {
            that.datainfo = res.data.statistics;
            that.quality_list = res.data.statistics.quality_list;
            that.sex_list = res.data.statistics.sex_list;
            that.age_list = res.data.statistics.age_list;
            that.cityData = res.data.statistics.area_list;
            that.productData = res.data.statistics.commission_list;
            that.initChart();
          } else {
            app.error(res.msg);
          }
        }
      );
    },
    range2(newval) {
      return;
      const that = this;
      const [start_day, end_day] = that.range2;
      that.showPicker2 = false;
      app.get(
        "MemberNote/noteMemberStatistics",
        {
          start_day: start_day,
          end_day: end_day,
        },
        function (res) {
          that.loaded();
          if (res.status == 200) {
            that.datainfo = res.data.statistics;
            that.quality_list = res.data.statistics.quality_list;
            that.sex_list = res.data.statistics.sex_list;
            that.age_list = res.data.statistics.age_list;
            that.cityData = res.data.statistics.area_list;
            that.productData = res.data.statistics.commission_list;
            that.initChart();
          } else {
            app.error(res.msg);
          }
        }
      );
    },
  },

  mounted() {
    this.getThemeColor();
    this.getdata();
  },
  methods: {
    touchStart(e) {
      if (this.isRefreshing) return;
      this.startY = e.touches[0].clientY;
    },
    touchMove(e) {
      if (this.isRefreshing) return;
      const scrollTop =
        document.documentElement.scrollTop || document.body.scrollTop;
      if (scrollTop > 0) return;

      const moveY = e.touches[0].clientY;
      const distance = moveY - this.startY;

      if (distance > 0) {
        e.preventDefault();
        this.refreshHeight = Math.min(distance / 2, this.maxPullHeight);
        this.refreshText =
          this.refreshHeight >= this.maxPullHeight
            ? "释放立即刷新"
            : "下拉刷新";
      }
    },
    touchEnd() {
      if (this.isRefreshing) return;

      if (this.refreshHeight >= this.maxPullHeight) {
        this.isRefreshing = true;
        this.refreshHeight = 50;
        this.refreshText = "正在刷新...";

        // 调用刷新数据的方法
        this.getdata().then(() => {
          setTimeout(() => {
            this.isRefreshing = false;
            this.refreshHeight = 0;
            this.refreshText = "下拉刷新";
          }, 500);
        });
      } else {
        this.refreshHeight = 0;
      }
    },

    confirm(e) {
      this.start_day = this.formatDate(e[0]);
      this.end_day = this.formatDate(e[1]);
      this.showPicker = false;
      this.showPicker2 = false;
      this.getdata();
    },

    getDate() {
      console.log(this.range);
      if (this.range) {
        this.start_day = this.range[0];
        this.end_day = this.range[1];
        this.showPicker = false;
        this.getdata();
      }
    },
    async getdata(type = null) {
      try {
        if (type == 0) {
          // 获取当前日期
          const today = new Date();
          // 计算7天前的日期（最后一天是昨天，所以7天前是 today - 6 days）
          const firstDay = new Date(today);
          firstDay.setDate(today.getDate() - 7); // 7天前（含今天的话是-6）

          // 昨天（近7天的最后一天）
          const lastDay = new Date(today);
          lastDay.setDate(today.getDate() - 1);
          this.start_day = this.formatDate(firstDay);
          this.end_day = this.formatDate(lastDay);
        }

        const response = await getNoteMemberStatistics({
          needinit: 1,
          start_day: this.start_day,
          end_day: this.end_day,
        });
        if (response.status == 200) {
          this.datainfo = response.data.statistics;
          console.log(response.data.statistics);
          this.pageviews1 = response.data.statistics.pageviews;
          console.log(this.pageviews1);
          this.quality_list = response.data.statistics.quality_list;
          this.sex_list = response.data.statistics.sex_list;
          this.age_list = response.data.statistics.age_list;
          this.cityData = response.data.statistics.area_list;
          this.productData = response.data.statistics.commission_list;
          this.initChart();
        }
        if (response._initdata) {
          this.$store.commit("theme/SET_COLOR", {
            key: "color1",
            value: response._initdata.color1,
          });
          this.$store.commit("theme/SET_COLOR", {
            key: "color2",
            value: response._initdata.color2,
          });
        }
      } catch (error) {
        console.error("刷新数据失败:", error);
      }

      return;
      const that = this;
      // 获取当前日期
      const today = new Date();

      // 计算7天前的日期（最后一天是昨天，所以7天前是 today - 6 days）
      const firstDay = new Date(today);
      firstDay.setDate(today.getDate() - 7); // 7天前（含今天的话是-6）

      // 昨天（近7天的最后一天）
      const lastDay = new Date(today);
      lastDay.setDate(today.getDate() - 1);

      // 格式化日期（示例：YYYY-MM-DD）
      const formatDate = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        return `${year}-${month}-${day}`;
      };
      const start_day = formatDate(firstDay);
      const end_day = formatDate(lastDay);
      app.get(
        "MemberNote/noteMemberStatistics",
        {
          start_day: start_day,
          end_day: end_day,
        },
        function (res) {
          that.loaded();
          if (res.status == 200) {
            that.datainfo = res.data.statistics;
            that.quality_list = res.data.statistics.quality_list;
            that.sex_list = res.data.statistics.sex_list;
            that.age_list = res.data.statistics.age_list;
            that.cityData = res.data.statistics.area_list;
            that.productData = res.data.statistics.commission_list;
            that.initChart();
          } else {
            app.error(res.msg);
          }
        }
      );
    },
    getThemeColor() {
      appIndex({ needinit: 1 }).then((response) => {
        if (response.status == 1) {
          if (response._initdata) {
            this.$store.commit("theme/SET_COLOR", {
              key: "color1",
              value: response._initdata.color1,
            });
            this.$store.commit("theme/SET_COLOR", {
              key: "color2",
              value: response._initdata.color2,
            });
          }
        }
      });
    },
    initChart() {
      this.option = {
        backgroundColor: "#ffffff",
        legend: {
          // x:"70%",
          show: true,
          type: "plain",
          left: "right",
          top: "middle",
          width: 100,
          height: "80%", //图例容器的高度，超过会换行展示
          orient: "vertical",
          //itemGap: 20, //设置图例的间距
          // y: '22%',
          // x: '50%',
          data: this.xy_data,
        },
        series: [
          {
            center: ["40%", "50%"], //饼图位置
            // 数据全为0也显示扇区
            stillShowZeroSum: true,
            // 是否高亮
            legendHoverLink: true,
            // 玫瑰图
            // roseType: 'area',
            name: "",
            // 如果有两个值，则为圆环图，第一个值为内半径，第二个值为外半径
            // radius: ['20%', '60%'],
            radius: "60%",
            // 饼状图标签
            label: {
              show: true,
              // 标签显示的位置，默认为outside
              // position: 'inside',
              // 字符串模板,可对文本标签内容进行设置
              //{a}：系列名。{b}：数据名。{c}：数据值。{d}：百分比。等等，详细见网站
              //formatter: '{b}:{d}%',
              formatter: (params) => {
                if (params.percent) {
                  return (
                    params.name +
                    " " +
                    params.value +
                    "\n\r(" +
                    params.percent +
                    "%)"
                  );
                }
                return params.name + " " + params.value + "\n\r(0%)";
              },
            },
            // 此系列自己的调色盘。优先级高于全局颜色配置
            // color: [
            //   '#dd6b66',
            //   '#759aa0',
            //   '#e69d87',
            //   '#8dc1a9',
            //   '#ea7e53',
            //   '#eedd78',
            //   '#73a373',
            // ],
            type: "pie",
            data: this.sex_list,
            grid: {
              //  top: '0px',
              left: "0px",
              //  right: '0px',
              bottom: "0px",
            },
          },
        ],
      };
      this.option2 = {
        textStyle: {
          color: "#666666",
          fontSize: "14px",
        },
        grid: {
          top: "24%",
          left: "5%",
          right: "4%",
          bottom: "0%",
          containLabel: true,
        },
        tooltip: {
          show: true,
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: this.dateRange,
          axisLine: {
            lineStyle: {
              color: "#eee",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            interval: 0, // 强制显示所有标签
          },
        },

        yAxis: {
          type: "value",
          offset: 10,
          splitLine: {
            lineStyle: {
              type: "dashed",
              color: "#e0e0e0",
            },
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            name: "浏览数",
            type: "bar",
            itemStyle: {
              color: "#579695",
              borderRadius: [4, 4, 0, 0], // 可选的圆角效果
            },
            barWidth: "50%", // 控制柱子的宽度
            data: this.age_list,
          },
        ],
      };
    },
    maskClick(e) {
      console.log("maskClick事件:", e);
    },

    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },

    getLast7Days() {
      const days = [];
      for (let i = 6; i >= 0; i--) {
        const date = new Date();
        date.setDate(date.getDate() - i);

        const month = (date.getMonth() + 1).toString().padStart(2, "0");
        const day = date.getDate().toString().padStart(2, "0");

        days.push(`${month}-${day}`);
      }
      return days;
    },
    // 上一页
    product_prevPage() {
      if (this.currentPage_product > 1) {
        this.currentPage_product--;
      }
    },
    // 下一页
    product_nextPage() {
      if (this.currentPage_product < this.productPages) {
        this.currentPage_product++;
      }
    },
    // 上一页
    prevPage() {
      if (this.currentPage > 1) {
        this.currentPage--;
      }
    },
    // 下一页
    nextPage() {
      if (this.currentPage < this.totalPages) {
        this.currentPage++;
      }
    },
    toDetail() {
      let id = this.datainfo.member_note.id;
      //   uni.navigateTo({
      //     url: "/pagesEchart/find/works-detail?id=" + id + "&type=0",
      //   });
      this.commonFun.jumpToMiniProgram(
        "/pagesEchart/find/works-detail?id=" + id + "&type=0"
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.statistics-container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 15px 10px;
}

.header {
  padding: 10px 0;
  background: #fff;
  border-radius: 6px;
  margin-bottom: 10px;

  .title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    padding: 0 10px;
  }
}

.data-overdiv {
  background: #fff;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;

  .overdiv-header {
    margin-bottom: 10px;

    .header-title {
      font-size: 16px;
      font-weight: bold;
      color: #333;
    }
  }

  .overdiv-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;

    .grid-item {
      text-align: left;

      .item-label {
        font-size: 14px;
        color: #666;
        margin-bottom: 4px;
        text-align: center;
      }

      .item-value {
        font-size: 16px;
        font-weight: bold;
        margin: 4px 0;
        color: #333;
        text-align: center;
      }

      .item-trend {
        font-size: 13px;
        color: #999;
        text-align: center;

        &.up {
          color: #ff6b6b;
        }
      }
    }
  }

  .note-prediv {
    display: flex;
    padding: 10px;
    background: #f8f8f8;
    border-radius: 4px;

    .note-image {
      width: 60px;
      height: 60px;
      border-radius: 4px;
      margin-right: 10px;
    }

    .note-info {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .note-t {
        color: #666;
        border-radius: 10px;
        padding: 2px 6px;
        font-size: 11px;
        display: inline;
        margin-bottom: 4px;
      }

      .note-info-flex {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .note-title {
        font-size: 16px;
        color: #333;
        margin-bottom: 5px;
        word-break: break-all;
        text-overflow: ellipsis;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        display: inline;
      }

      .note-stats {
        font-size: 12px;
        color: #999;

        span {
          margin-right: 10px;
        }
      }
    }

    .note-info-span {
      color: rgba(16, 16, 16, 1);
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}

.trend-section {
  background: #fff;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;

  .trend-header {
    margin-bottom: 10px;

    .section-title {
      font-size: 16px;
      font-weight: bold;
      color: #333;
      display: flex;
      justify-content: space-between;
    }

    .date-range {
      font-size: 12px;
      color: #666;
      margin-top: 10px;

      span {
        margin-left: 10px;
        padding: 2px 6px;
        border-radius: 10px;

        &.active {
          background: #f0f0f0;
        }
      }
    }
  }

  .trend-chart {
    .chart-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 10px;
      font-size: 12px;

      .chart-header-border {
        border: 1px solid #eee;
        padding: 5px;
        border-radius: 10px;
        width: 84px;
      }

      .chart-label {
        color: #666;
      }

      .chart-value {
        color: #333;
        font-size: 20px;
        font-weight: bold;
      }
    }
  }

  .chart-container {
    // height: 150px;
    // margin: 10px 0;
  }
}

.source-analysis {
  background: #fff;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;

  .analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;

    .section-title {
      font-size: 16px;
      font-weight: bold;
      color: #333;
    }

    .date-selector {
      font-size: 12px;

      span {
        margin-left: 10px;

        &.active {
          color: #666;
        }

        &.note-t {
          color: #666;
          padding: 2px 6px;
          border-radius: 10px;
        }
      }
    }
  }

  .pie-container {
    height: 200px;
    position: relative;
  }
}

.quality-notes {
  background: #fff;
  border-radius: 6px;
  padding: 10px;

  .notes-header {
    margin-bottom: 10px;

    .section-title {
      font-size: 16px;
      font-weight: bold;
      color: #333;
    }
  }

  .notes-list {
    .note-item {
      display: flex;
      padding: 10px 0;
      border-bottom: 1px solid #f5f5f5;

      &:last-child {
        border-bottom: none;
      }

      .note-image {
        width: 60px;
        height: 60px;
        border-radius: 4px;
        margin-right: 10px;
        flex-shrink: 0;
      }

      .note-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;

        .note-span {
          font-size: 13px;
          color: #333;
          margin-bottom: 7px;
          display: -webkit-box;
          -webkit-line-clamp: 2;

          -webkit-box-orient: vertical;

          overflow: hidden;

          text-overflow: ellipsis;

          .flex-a {
            border-radius: 10px;
            padding: 3px;
            font-size: 12px;
          }
        }

        .note-tag {
          display: flex;
          gap: 5px;
          flex-wrap: wrap;
          font-size: 13px;
          color: #333;
          margin-bottom: 7px;

          .flex-a {
            border-radius: 10px;
            padding: 3px;
            font-size: 12px;
          }
        }

        .note-interactions {
          font-size: 12px;
          color: #999;
          display: flex;
          justify-content: space-between;

          span {
            margin-right: 15px;
          }
        }
      }
    }
  }
}

.note-interactions-icon {
  width: 15px;
  height: 15px;
}

.flex-a {
  display: flex;
  align-items: center;
  color: rgba(16, 16, 16, 1);
}

/* 表格容器 */
.data-table-container {
  margin-top: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* 平滑滚动 */
}

/* 表格整体样式 */
.data-table {
  width: 100%;

  /* 最小宽度保证列宽固定 */
  border-collapse: collapse;
  border: 1px solid #e0e0e0;
  font-size: 14px;
}

/* 表格行 */
.table-row {
  display: flex;
  border-bottom: 1px solid #e0e0e0;
}

.table-row:last-child {
  border-bottom: none;
}

/* 表头样式 */
.header-row {
  background-color: #f7f8fa;
  font-weight: bold;
  // color: #333;
}

/* 基础单元格样式 */
.table-cell {
  padding: 12px 8px;
  border-right: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  box-sizing: border-box;
  overflow: hidden;
  text-align: center;
}

/* 移除最后一列的右边框 */
.table-cell:last-child {
  border-right: none;
}

/* 固定列宽设置 */
.rank-cell {
  width: 15%;
  flex: 0 0 auto;
}

.product-cell {
  width: 30%;
  flex: 0 0 auto;
  flex-direction: column;
}

.amount-cell {
  width: 20%;
  flex: 0 0 auto;
}

.volume-cell {
  width: 15%;
  flex: 0 0 auto;
}

.rate-cell {
  width: 20%;
  flex: 0 0 auto;
}

/* 商品单元格特殊样式 */
.product-img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.product-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 内容溢出隐藏 */
.table-cell > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

.city-num-cell {
  width: 20%;
  flex: 0 0 auto;
}

.city-cell {
  width: 40%;
  flex: 0 0 auto;
}

.year-box {
  font-weight: 700;
  margin-top: 10px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  padding: 10px 0;
}

.page-btn {
  margin: 0 10px;
  padding: 5px 15px;
  font-size: 14px;

  border-radius: 4px;
}

.page-btn:disabled {
  opacity: 0.5;
}

.page-info {
  font-size: 14px;
  color: #666;
}
.nodata-box {
  text-align: center;
  height: 100px;
  line-height: 100px;
}
.pull-refresh {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 0;
  background-color: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #666;
  transition: height 0.2s ease;
  z-index: 100;
}
</style>